package com.design.observer.genernal;



import java.util.ArrayList;
import java.util.List;

/**
 * 具体主题者
 *
 * @author: cong zhi
 * @createDate: 2023/8/2 10:54
 * @updateUser: cong zhi
 * @updateDate: 2023/8/2 10:54
 * @updateRemark: 修改内容
 * @version: v1.0
 */
public class ConcreteSubject<E> implements Subject<E> {


    private List<ObServer<E>> obServers = new ArrayList<>();


    public boolean attach(ObServer<E> obServer) {
        return !this.obServers.contains(obServer) && this.obServers.add(obServer);
    }

    public boolean detach(ObServer<E> obServer) {
        return this.obServers.remove(obServer);
    }

    @Override
    public void notify(E event) {
        for (ObServer<E> obServer : this.obServers) {
            obServer.update(event);
        }

    }
}
